package com.example.administrator.onepagelibrary.dagger;

import android.app.Activity;

import com.example.administrator.commonlibrary.bese.BaseAppliction;
import com.example.administrator.onepagelibrary.dagger.component.ActivityComponent;
import com.example.administrator.onepagelibrary.dagger.component.DaggerActivityComponent;
import com.example.administrator.onepagelibrary.dagger.module.ViewModule;
import com.example.administrator.onepagelibrary.dagger.module.ViewParameterModule;
import com.example.administrator.onepagelibrary.onebase.MainActivity;
import com.example.administrator.onepagelibrary.view.activity.HuadongActivity;

/**
 * 作者：wang_hong_wei
 * 创建时间：2018/9/17
 * 描述：
 */
public class NewActivityInject implements ActivityComponent{

    private ActivityComponent build;

    public static NewActivityInject getInject(){
        return new NewActivityInject();
    }
    public  <S, T> void inject(S module, T context) {
        if (module == null) module = (S) new ViewParameterModule((Activity) context);
        ViewModule mvpModule = new ViewModule((Activity) context);
        build = DaggerActivityComponent.builder().viewModule(mvpModule).viewParameterModule((ViewParameterModule) module).overallSituationComponent(BaseAppliction.getOverallSituation()).build();

        if (context instanceof HuadongActivity)inject((HuadongActivity) context);
        if (context instanceof MainActivity) inject((MainActivity) context);
    }

    @Override
    public void inject(MainActivity mainActivity) {
        build.inject(mainActivity);
    }

    @Override
    public void inject(HuadongActivity huadongActivity) {
        build.inject(huadongActivity);
    }
}
